
{extend name=".././view/list.html" /}
{block name="jsset"}

{/block}
{block name="nav"}
	<span class="layui-breadcrumb">
		<a href="">成绩查询</a>
    <a href="">班级查询</a>
		<a><cite>{$list.webtitle}</cite></a>
	</span>
{/block}
{block name="search"}

		<div class="layui-form-item">
          <label for="searchval" class="layui-form-label">
              关键字
          </label>
          <div class="layui-input-block">
              <input type="text" id="searchval" name="searchval"
              autocomplete="off" class="layui-input" placeholder="学生姓名" placeholder="输入关键字并回车">
          </div>
    </div>
    
		<input type="hidden" id="kaoshi_id" name="kaoshi_id" value="{$list.kaoshi_id}">
    <input type="hidden" id="banji_id" name="banji_id" value="{$list.banji_id}">
    <input type="hidden" id="subject_id" name="subject_id" value="{$list.subject_id}">

{/block}
{block name="table"}
	<table id="tabledemo" lay-filter="mytable" lay-size="sm"></table>
{/block}
{block name="myjs"}
<!-- 表格上面按钮模板 -->
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn" lay-event="download">
      <i class="layui-icon layui-icon-download-circle"></i> 下载
    </button>
  </div>
</script>
<!-- 记录操作按钮模板 -->
<script type="text/html" id="barDemo">
  <a class="layui-btn-xs" lay-event="detail" title="录入信息"><i class="layui-icon layui-icon-search"></i></a>
  <a class="layui-btn-xs" lay-event="chengji" title="成绩图表"><i class="layui-icon layui-icon-chart-screen"></i></a>
  <a class="layui-btn-xs" lay-event="del" title="删除考号"><i class="layui-icon">&#xe640;</i></a>
</script>
<!-- 表格操作 -->
<script>
	// 设置列
	options.cols=[[ //表头
		{type:'checkbox', fixed: 'left'},
		{field: "student", title: '学生姓名',sort: true, minWidth:100},
    {field: "defen", title: '得分',sort: true, minWidth:100},
    {field: "defenlv", title: '得分率',sort: true, minWidth:100},
    {field: "bweizhi", title: '班级位置',sort: true, minWidth:100},
    {field: "xweizhi", title: '学校位置',sort: true, minWidth:100},
	]];

	// 设置每页显示条数
	options.limit = 10;
	options.limits = [10,15];

	// 提交搜索条件后重载表格
    layui.use(['table','cjgl'],function(){
      var table = layui.table
      		cjgl = layui.cjgl;

      addBanji();

      //表头工具栏事件
      table.on('toolbar(mytable)', function(obj){
      	switch(obj.event){
          case 'download':
            layer.msg('下载？算了吧~');
            break;
            cjgl.add('下载成绩条','/chengji/index/dwchengjitiao/{$list.kaoshi_id}','650','300');
            break;
      	};
      });

      //监听行工具条
      table.on('tool(mytable)', function(obj){
      	var data = obj.data; //获得当前行数据
      	var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      	var tr = obj.tr; //获得当前行 tr 的DOM对象
      	switch(layEvent){
      		case 'detail':// 查看
            cjgl.add(obj.data.student_xingming + ' 成绩录入信息','/chengji/index/readcjadd/' + obj.data.id, '', '', true);
            break;
          case 'chengji':// 查看
            cjgl.add(obj.data.student_xingming + ' 成绩图表','/kaohao/index/read/' + obj.data.id, '', '', true);
            break;
      		case 'del':// 删除
	      		cjgl.del(obj,"/kaohao/index/delete");
	      		break;
      	};
      });

      // 单元格编辑
      table.on('edit(mytable)',function(obj){
      	// 声明变量
      	var newdefen = obj.value
      		,colname = obj.field
      		,rowdata = obj.data;

      	// 修改服务器数据
        $.ajax({
          url:"/chengji/luru/update/"+rowdata.id,
          type:'PUT',
          data:{
              "colname":colname,
              "newdefen":newdefen
          },
          success:function(result,obj){
              if(result.val == 0 || result.code==0)
              {
                layer.msg(result.msg,{icon:5});
              }else{
              	// 这个地方重新赋值平均分和总分
              }
          },
          error:function(result){
              layer.msg('数据扔半道啦。',function(){});
          },
        });
      });

      // 监听表单提交
      form.on('radio', function(data){
        addBanji();
        $("#srcsubmit").click();
      });

      // 添加班级列表
      function addBanji(){
        // 获取参数
        var formval = form.val('search');
        cjgl.createCheckbox('banji_id', formval, '/tools/kscy/class', 'banji_id', 'banTitle');
      }



    });
</script>
{/block}
